<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>任务交接</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
<div class="Wrapper">
    <table class="layout2col1">
        <tbody>
            <tr>
                <td style="width: 350px;" valign="top">
                    <div style="width: 350px;" class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_3"></i>组织架构</span>
                        </div>
                        <div class="sqPanel_body" style="min-height: 300px;">
                            <div class="btnsBox">&nbsp;</div>
                            <div class="nanoWrap" style="height: 360px;">
                                <div class="nano"><div class="nano-content">
                                    <ul id="tree1">
                                    </ul>
                                </div></div>
                            </div>
                        </div>
                    </div>
                </td>
                <td valign="top">
                    <div style="width: 680px;" class="sqPanel">
                        <div class="sqPanel_head">
                            <form id="searchBar2" class="titSearchBar">
                                <div class="fieldset1 clearFix">
                                    <div class="fieldBox">
                                        <div class="label">用户</div>
                                        <div class="field">
                                             <input name="usrNm" id="usrNm" type="text" class="ui-textbox" value="">
                                        </div>
                                    </div>
                                    <span id="searchBtn2" class="sq-search-button"></i>查询</span>
                                </div>
                            </form>
                        </div>
                        <div class="sqPanel_body">
                            <div class="FBL5">
                                <span id="savePE_btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_18"></i>确定</span>
                            </div>
                            <div id="ligergrid_PE" class="sq-grid"></div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>

    <div id="addPE_Html" style="display:none">
        <form id="searchBar_addPE" class="l-form">
            <div class="fieldset1 clearFix">
                <div class="FBL5" style="padding: 0;">
                    <div class="fieldBox">
                        <div class="label">用户名</div>
                        <div class="field">
                             <input name="usrNmSearch" id="usrNmSearch" type="text" class="ui-textbox" value="" ligerui="width: 100">
                        </div>
                    </div>
                    <span id="searchBtn_addPE" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                </div>
            </div>
        </form>
        <input id="type" value="${type}" style="display:none">
    </div>
<script type="text/javascript">
var type = '${type}';
var tree,
    grid_PE,
    grid_addPE;
$(function () {
    tree = $("#tree1").ligerTree({
    	url: '<%=path%>/system/sysOrg/initList.do',
        ajaxType: 'get',
        checkbox: false,
        // single: true,
        parentIcon: "SqFolder",
        childIcon: "SqLeaf",
        needCancel:false,
        isExpand: false,
        isLeaf: function (data) {
            if (!data) return false;
            if (data.hasChildren) {return false} else if(data.children){return false} else {return true};
        },
        onSelect: function (node) {
            set_ligergrid_PE (node.data.id);
        },
        onSuccess: function (data) {
            setNanoScroller();
            tree.selectNode(data[0]);
        }
    });

    $("#searchBar2").ligerForm();
    $("#searchBtn2").click(function(event) {
        if (!tree.getSelected()) {
             $.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_ORG,SQ_type: "warning"});
            return;
        };
        var form=liger.get("searchBar2");
        var data = form.getData();
            data.structureID=tree.getSelected().data.id;
        //alert(JSON.stringify(data));
        for (name in data) {grid_PE.setParm(name, data[name])};
        grid_PE.reload();
    });

    $("#searchBtn_addPE").click(function(event) {
        var form=liger.get("searchBar_addPE");
        var data = form.getData();
            data.structureID=tree.getSelected().data.id;
        //alert(JSON.stringify(data));
        for (name in data) {grid_addPE.setParm(name, data[name])};
        grid_addPE.reload();
    });
    $("#deletePE_btn").click(function(event) {
        if (!tree.getSelected()) {
        	 $.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_ORG,SQ_type: "warning"});
            return;
        };
        var selectedRoles=grid_PE.getSelecteds();
        if (selectedRoles.length==0) {
        	  $.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_USR,SQ_type: "warning"});
            return;
        };
        var usrIdArr=[];
        var hasSysDefRec = false;//是否包含系统默认数据
        for (var i = 0; i < selectedRoles.length; i++) {
        	usrIdArr.push(selectedRoles[i].id);
        	//判断是否是系统内置,如果有系统内置则不能删除
        	if(selectedRoles[i].isSysDefFromDataAuth && (selectedRoles[i].isSysDefFromDataAuth == CommonConstant.C_YN_Y)){
        		hasSysDefRec = true;
        		break;
        	}
        };
        //如果有系统内置数据则不能操作
        if(hasSysDefRec){
        	 $.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_INSIDE_FORBID_HANDLE,SQ_type: "warning"});
        	return;
        }

        var DATA={
        	usrIdArr: usrIdArr,
            orgId: tree.getSelected().data.id
        }
        //alert(JSON.stringify(DATA));
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
	        $.ajax({
	  			type: 'post',
	  			dataType:'json',
	  			data:DATA,
	  			url: '<%=path%>/system/sysUsrDatAuthR/removeSysUsrDatAuthR.do',
	  			success:function(msg){
	  				 if(msg.success == 1){
	  					 $.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	  					grid_PE.reload();
	  				 }else{
	  					 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	  				 }
	  			}
	  		});
        });
    });
});
function set_ligergrid_PE (orgId) {
    var parms={
        "orgId":orgId
    };
    if (grid_PE) {
        grid_PE.grid.show();
        for (name in parms) {grid_PE.setParm(name, parms[name])};
        grid_PE.reload();
    }else{
        render_ligergrid_PE (parms)
    };
}
function render_ligergrid_PE (parms) {
    grid_PE = $("#ligergrid_PE").ligerGrid({
    	url: '<%=path%>/system/sysUsr/getUsrByOrgId.do',
        parms: parms,
        root:'rows',
        record:'total',
        method : 'get',
        fixedCellHeight: false,
        checkbox: true,
        selectRowButtonOnly: false,
        isSingleCheck: true,
        frozenCheckbox: false,
        allowHideColumn: false,
        rownumbers:true,
        columns: [{
        	display: '组织架构',
            name: 'orgCdNm',
            minWidth: 120,
            render: function (rowdata, rowindex, value){
        		return UIUtils.showColumnTip(value);
            }

        }, {
        	display: '用户名',
            name: 'usrNm',
            minWidth: 120

        }, {
        	display: '真实名称',
            name: 'refRlNm',
            minWidth: 120
        },{
            display: '是否主管',
            name: 'isChgNm',
            minWidth: 120,
        },{
            display: '系统内置',
            name: 'isSysDefNmFromDataAuth',
            minWidth: 120
        }],
        height:'100%',
        heightDiff:-2,
        hideLoadButton : true,
        usePagerOnLessPagesize: true
    });

    grid_PE.setHeight(100);
}
function setNanoScroller () {
    $(".nanoWrap .nano").nanoScroller({
        preventPageScrolling: true
    });
}
//修改中的保存按钮
$("#savePE_btn").click(function(){
	var selectedRows = grid_PE.getSelectedRows();
	if (selectedRows.length != 1) {
        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
        return;
    }
	var usrId = "";
	var refRlNm = "";
	for ( var index in selectedRows) {
		usrId = selectedRows[index].id;
		refRlNm = selectedRows[index].refRlNm;
		if(type == "owner"){
			parent.$("#ownerId").val(usrId);
 			parent.$("#ownerName").val(refRlNm);
		}
		if(type == "assignee"){
			parent.$("#assigneeId").val(usrId);
 			parent.$("#assigneeName").val(refRlNm);
		}
	}
	parent.$.ligerDialog.close();
	parent.$(".l-dialog,.l-window-mask").css("display","none");
});
</script>

</body>
</html>
